package org.apache.cordova.phone;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;

import android.content.Intent;
import android.net.Uri;

public class PhoneDialer extends CordovaPlugin {

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.cordova.api.CordovaPlugin#execute(java.lang.String,
	 * org.json.JSONArray, org.apache.cordova.api.CallbackContext)
	 */
	@Override
	public boolean execute(String action, JSONArray args,
			CallbackContext callbackContext) throws JSONException {
		if (action.equals("dial")) {
			String message = args.getString(0);
			Intent intent = new Intent(Intent.ACTION_DIAL);
			intent.setData(Uri.parse("tel:" + message));
			this.cordova.getActivity().startActivity(intent);
			return true;
		}
		return false;
	}
}
